;(function() {

	var MONTHS = ['January', 'February', 'March', 'April', 'May', 'June', 
		'July', 'August', 'September', 'October', 'November', 'December'];

	Nokia.GBCUtils = {
		
		/*
		 * Resize an image accordingly to the width of its parent DOM node
		 */		
		normalizeImageWidth: function(event) {
			var imgElement = event.target;
			var imgWidth = imgElement.offsetWidth;
			imgElement.style.display = 'none';
			var maxImgWidth = imgElement.parentNode.offsetWidth - 10;

			if(imgWidth > maxImgWidth)
			{
				var w = maxImgWidth;
				var h = w * imgElement.offsetHeight / imgElement.offsetWidth;
				
				imgElement.style.width = w + 'px';
				imgElement.style.height = h + 'px';
			}
			imgElement.style.display = '';
		},
		
		/* 
		 * Parse the weather date string, as returned from the weather Web service
		 */
		parseWeatherDate: function(dateString)
		{
			var year = parseInt(dateString.substring(0, 4));
			var month = parseInt(dateString.substring(5, 7), 10);
			var day = parseInt(dateString.substring(8, 10), 10);
			var hour = parseInt(dateString.substring(11, 13), 10);
			var minute = parseInt(dateString.substring(14, 16), 10);
			var second = parseInt(dateString.substring(17, 19), 10);
			
			var d = new Date(year, month, day, hour, minute, second);
			
			return d;
		},
		
		/*
		 * The following section defines a set of date-formatting utility methods
		 */

		formatLongDate: function(date)
		{
			return date.getDate() + " " + MONTHS[date.getMonth()] + " " + date.getFullYear();
		},
		formatDate: function(date)
		{
			return this._normalize(date.getDate()) + "/" + this._normalize(date.getMonth());
		},
		formatDateTime: function(date)
		{
			return this._normalize(date.getDate()) + "/" + this._normalize(date.getMonth()) + "/" + date.getFullYear() + " at " + 
				this._normalize(date.getHours()) + ":" + this._normalize(date.getMinutes());
		},
		formatTime: function(date)
		{
			return this._normalize(date.getHours()) + ":" + this._normalize(date.getMinutes());
		},
		_normalize: function(num)
		{
			return num < 10 ? '0' + num : num;
		}
	};
})();